/********************************
 * ETK - Easy ToolKit
 * Copyright (C) 2007-2008 Ekinoks (scv.ekinoks@gmail.com)
 * All rights reserved.
 *
 *    This file is part of ETK.
 *
 *    Foobar is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    Foobar is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Foobar; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 ***********************************************************************************/



#include "CallBackI.h"

#include <iostream>

#include "../../define.h"
#include "../../Widget/Widget.h"
#include "../../Render/Render.h"
#include "../../Render/ToolKit/ToolKit.h"
#include "../../Event/Event.h"

#include <gtk/gtk.h>

namespace etk
{
    CallBackI::CallBackI(Widget *widget_, int event_, bool after) : widget(widget_)
    {
        // on dit au widget qu'il est lié avec ce callback (pour gerer corectement les deletes)
        widget->add_call_back(this);

        // on connect le signal
        if(after)
            id_signal = TOOL_KIT.signal_connect_after(widget->getRWidget(), event_, this);
        else
            id_signal = TOOL_KIT.signal_connect(widget->getRWidget(), event_, this);
    }

    CallBackI::~CallBackI()
    {
        // on dit au widget qu'il n'est plus lié avec ce callback
        print_section("~CallBackI");
        widget->remove_call_back(this);

        if(TOOL_KIT.signal_is_connected(widget->getRWidget(), id_signal))
            TOOL_KIT.signal_disconnect(widget->getRWidget(), id_signal);
    }

    void CallBackI::block() const
    {
        TOOL_KIT.signal_block(widget->getRWidget(), id_signal);
    }

    void CallBackI::unblock() const
    {
        TOOL_KIT.signal_unblock(widget->getRWidget(), id_signal);
    }

}
